<template>
  <div class="page-header-index-wide">
    <a-card :bordered="false" :bodyStyle="{ padding: '16px 0', height: '100%' }" :style="{ height: '100%' }">
      <div class="account-settings-info-main">
        <div class="account-settings-info-right">
          <div class="account-settings-info-title">
            <span>修改密码</span>
          </div>
          <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
            <!-- <div style="width: 320px;margin-top: 10px;">
              <label style="width: 80px;display: block;float: left;text-align: right;">账号ID</label>
              <a-input :disabled="true" style="width: 220px;margin-left: 10px;" v-model="formData.id"/>
            </div> -->
            <div style="width: 350px;margin-top: 10px;">
              <label style="width: 120px;display: block;float: left;text-align: right;">登录账号</label>
              <a-input :disabled="true" style="width: 220px;margin-left: 10px;" v-model="formData.mobile"/>
            </div>
            <!-- <div style="width: 350px;margin-top: 10px;">
              <label style="width: 120px;display: block;float: left;text-align: right;"><span style="color: red;">*</span>正在使用的密码</label>
              <a-input-password style="width: 220px;margin-left: 10px;" v-model="formData.pwd"/>
            </div> -->
            <div style="width: 350px;margin-top: 10px;">
              <label style="width: 120px;display: block;float: left;text-align: right;"><span style="color: red;">*</span>新密码</label>
              <a-input-password style="width: 220px;margin-left: 10px;" v-model="formData.newPwd"/>
            </div>
            <div style="width: 350px;margin-top: 10px;">
              <label style="width: 120px;display: block;float: left;text-align: right;"><span style="color: red;">*</span>确认密码</label>
              <a-input-password style="width: 220px;margin-left: 10px;" v-model="formData.confirm_password"/>
            </div>
            <div style="width: 350px;">
              <a-button style="margin-top: 20px; float: right;" @click="onCheckPasswordStrength" type="primary">确认</a-button>
              <a-button style="margin-top:20px; margin-right: 10px; float: right;" @click="$router.go(-1)">返回</a-button>
            </div>
          </a-card>
        </div>
      </div>
    </a-card>
  </div>
</template>

<script>
import { RouteView } from '@/layouts'
import { baseMixin } from '@/store/app-mixin'
import { CheckPasswordStrength, ResetPassword } from '@/api/login'
import { message } from 'ant-design-vue'
import { mapState } from 'vuex'
export default {
  components: {
    RouteView
  },
  mixins: [baseMixin],
  data () {
    return {
      openKeys: [],
      selectedKeys: [],
      formData: {
        mobile: '',
        pwd: '',
        newPwd: '',
        confirm_password: ''
      }
    }
  },
  mounted () {
    this.formData.mobile = this.info.mobile
  },
  computed: {
    ...mapState({
      info: state => state.user.info
    })
  },
  methods: {
    onResetPassword () {
      const self = this
      // 修改密码
      const form = {
        password: self.formData.newPwd,
        confirm_password: self.formData.confirm_password
      }
      ResetPassword(form).then((res) => {
        if (res.is_ok === 'Y') {
          self.formData = {}
          message.success('修改密码成功')
          this.$router.go(-1)
        }
      })
    },
    onCheckPasswordStrength () {
      // 校验密码
      const self = this
      if (self.formData.newPwd === '') {
        message.warning('密码不能为空')
        return
      }
      if (self.formData.newPwd !== self.formData.confirm_password) {
        message.warning('两次密码不一致,请重新输入')
        return
      }
      // 校验密码等级
      CheckPasswordStrength({ password: self.formData.newPwd }).then((res) => {
        if (res !== null) {
          self.onResetPassword()
        }
      })
    }
  },
  watch: {
  }
}
</script>

<style lang="less" scoped>
  .account-settings-info-main {
    width: 100%;
    display: flex;
    height: 100%;
    overflow: auto;

    &.mobile {
      display: block;

      .account-settings-info-left {
        border-right: unset;
        border-bottom: 1px solid #e8e8e8;
        width: 100%;
        height: 50px;
        overflow-x: auto;
        overflow-y: scroll;
      }
      .account-settings-info-right {
        padding: 20px 40px;
      }
    }

    .account-settings-info-left {
      border-right: 1px solid #e8e8e8;
      width: 224px;
    }

    .account-settings-info-right {
      flex: 1 1;
      padding: 8px 40px;

      .account-settings-info-title {
        color: rgba(0,0,0,.85);
        font-size: 20px;
        font-weight: 500;
        line-height: 28px;
        margin-bottom: 12px;
      }
      .account-settings-info-view {
        padding-top: 12px;
      }
    }
  }

</style>
